Open for Access
The Open for Access command opens access to a file for reading or writing using the Read and Write commands. Opening a file for reading and writing is not the same as opening it with the Open command. The file is open only in the sense that AppleScript has access to it for reading and writing data; it doesn't appear in one of the target application's windows, and it doesn't even have to be one of the target application's files.Open for Access is one of several commands provided by the Read/Write Commands scripting addition. For more information about these commands, see "Using Read/Write Commands,".
SYNTAX
open for access referenceToFile [ write permission Boolean ]PARAMETERS
- referenceToFile
- A reference of the form
file
nameString oralias
nameString. If you specify an alias, the file must already exist, because AppleScript must locate the file before running the script. If you specify a file that doesn't exist using the formfile
nameString, Open for Access creates a TeachText document of that name at the specified location and opens it for access.
Class: Reference- Boolean
- An expression that evaluates to
true
orfalse
. If it evaluates totrue
, AppleScript opens the file with read and write permission. If it evaluates tofalse
or if this parameter is omitted entirely, AppleScript opens the file with read permission only. Note that the phrasewith write permission
is equivalent to the phrasewrite permission true
; similarly,without write permission
is equivalent towrite permission false
.
Class: BooleanRESULT
File reference number.EXAMPLE
This example opens the file named To Donald in the specified location for subsequent access with the Read command.
tell application "Scriptable Text Editor" open for access file "Hard Disk:Letters:To Donald"end tellThe next example opens the file associated with the file reference number for subsequent access with the Read or Write command.
tell application "Scriptable Text Editor" open for access alias "Hard Disk:Aliases:To Donald" ¬ with write permission end tellNOTES
To specify the name (nameString) of a file, use a string of the form"Disk:Folder1:
as described in Chapter 5, "Objects and References,"
Folder2:...:Filename"
of the AppleScript Language Guide. If you specify only the name of the file (Filename) instead of its entire pathname, AppleScript attempts to find the file in the current directory.ERRORS